{%- set separator = ' ' %}
{%- set export_dir = salt['pillar.get']('default:OMV_NFSD_EXPORT_DIR', '/export') -%}
{%- set v4_default_options = salt['pillar.get']('default:OMV_NFSD_V4_DEFAULT_EXPORT_OPTIONS', 'ro,fsid=0,root_squash,no_subtree_check,hide') -%}
{%- set shares_v3 = salt['omv_conf.get_by_filter'](
  'conf.service.nfs.share',
  {'operator': 'distinct', 'arg0': 'sharedfolderref'}) -%}
{%- set shares_v4 = salt['omv_conf.get_by_filter'](
  'conf.service.nfs.share',
  {'operator': 'distinct', 'arg0': 'client'}) -%}
{{ pillar['headers']['multiline'] }}
# /etc/exports: the access control list for filesystems which may be exported
#               to NFS clients.  See exports(5).
{%- for share_v3 in shares_v3 %}
{% set v3_loop = loop %}
{%- set shares = salt['omv_conf.get_by_filter'](
  'conf.service.nfs.share',
  {'operator': 'stringEquals', 'arg0': 'sharedfolderref', 'arg1': share_v3.sharedfolderref}) %}
{%- for share in shares %}
{%- set sharedfolder = salt['omv_conf.get']('conf.system.sharedfolder', share.sharedfolderref) %}
{%- if loop.first %}{{ export_dir | path_join(sharedfolder.name) }}{% endif -%}
{{ separator }}{{ share.client | trim }}(fsid={{ v3_loop.index }},{{ share.options }}{% if share.extraoptions | length > 0 %},{{ share.extraoptions }}{% endif %})
{%- endfor %}
{%- endfor %}

# NFSv4 - pseudo filesystem root
{%- for share_v4 in shares_v4 %}
{{ export_dir }} {{ share_v4.client | trim }}({{ v4_default_options }})
{%- endfor %}
